<?php
require_once APPLICATION_PATH.'/controllers/AbstractBaseController.class.php';

class IndexController extends AbstractBaseController
{
    public function init()
    {
        $this->view->pageHeader = 'Home';
    }

    public function indexAction()
    {
        if ($this->_request->isPost())
        {
            $storeName = $this->getRequestParameter('store');

            if (!empty($storeName))
            {
                $storeUri = 'http://api.talis.com/stores/'.$storeName;

                $this->getSessionManager()->setCurrentStore($storeUri);
                $this->_redirect('/store');
            }
        }
        else
        {
            /*
             * If store already set in session then back to the store page until uset decided to change store...
             */
            try
            {
                $currentStore = $this->getSessionManager()->getCurrentStore();
                $this->_redirect('/store');
            }
            catch (Exception $e)
            {
                // No store in session so just prompt for store.
            }

            if ($this->isParameterSet('invalidStore'))
            {
                $this->view->flashMessage = 'Invalid store';
                $this->view->flashMessageClass = 'msgError';
            }
        }
    }
}